package easy;

public class Solution_1854 {

    public int maximumPopulation(int[][] logs) {
        int max = Integer.MIN_VALUE, min = Integer.MAX_VALUE;
        for (int[] log : logs) {
            min = Math.min(min, log[0]);
            max = Math.max(max, log[1]);
        }
        int year = min, num = 0;
        for (int i = min; i <= max; i++) {
            int count = 0;
            for (int[] log : logs) {
                if (log[0] <= i && i < log[1]) {
                    count++;
                }
            }
            if (count > num) {
                num = count;
                year = i;
            }
        }
        return year;
    }

    /*public int maximumPopulation(int[][] logs) {
        int max = Integer.MIN_VALUE, min = Integer.MAX_VALUE;
        for (int[] log : logs) {
            min = Math.min(min, log[0]);
            max = Math.max(max, log[1]);
        }
        int[] counts = new int[max - min + 1];
        for (int[] log : logs) {
            for (int i = log[0]; i < log[1]; i++) {
                counts[i - min]++;
            }
        }
        int index = 0;
        for (int i = 1; i < counts.length; i++) {
            if (counts[i] > counts[index]) {
                index = i;
            }
        }
        return index + min;
    }*/

    public static void main(String[] args) {
        Solution_1854 model = new Solution_1854();
        System.out.println(model.maximumPopulation(
            new int[][]{{2008, 2026}, {2004, 2008}, {2034, 2035}, {1999, 2050}, {2049, 2050}, {2011, 2035},
                {1966, 2033}, {2044, 2049}}));
    }
}
